package com.spring.security.controller;/**
 * Title: ProductTestController
 * Description: TODO
 *
 * @author yls
 * @created 2019/11/28 14:52
 */

import com.alipay.api.domain.UserDetails;
import org.springframework.http.MediaType;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RequestMapping("/product")
public class ProductTestController {
    @RequestMapping("/info")
    @ResponseBody
    public String productInfo(){
        return " some product info ";
    }

    @RequestMapping("/info2")
    @ResponseBody
    public String productInfo2(){
        String currentUser="";
        Object principe= SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if(principe instanceof UserDetails){
            currentUser=((UserDetails) principe).getUserName();
        }else{
            currentUser=principe.toString();
        }
        return " some product info,currentUser is:"+currentUser;
    }

}